import request from '@/utils/request'

export default {
  getUserList(searchModel) {
    return request({
      url: '/user/list',
      method: 'get',
      params: {
        pageNo: searchModel.pageNo,
        pageSize: searchModel.pageSize,
        username: searchModel.username,
        uEmail: searchModel.uEmail
      }
    })
  },
  addUser(user) {
    return request({
      url: '/user',
      method: 'post',
      data: user
    })
  },
  updateUser(user) {
    return request({
      url: '/user',
      method: 'put',
      data: user
    })
  },
  saveUser(user) {
    if (user.uid == null || user.uid == undefined) {
      console.log('增加用户')
      return this.addUser(user)
    }
    console.log('修改用户')
    return this.updateUser(user)
  },
  getUserById(id) {
    return request({
      url: `/user/${id}`,
      method: 'get'
    })
  },
  deleteUserById(id) {
    return request({
      url: `/user/${id}`,
      method: 'delete'
    })
  },
  getUserInfo(token) {
    return request({
      url: '/user/info',
      method: 'get',
      params: {
        token
      }
    })
  }
}
